//
//  BaseTabbarCon.m
//  gungunchou
//
//  Created by lyzbmacos3 on 2018/12/4.
//  Copyright © 2018年 xskj. All rights reserved.
//

#import "BaseTabbarCon.h"

@interface BaseTabbarCon ()

@end

@implementation BaseTabbarCon

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImage *colorClearImage = [LJUtility imageWithColor:[UIColor clearColor] size:CGSizeMake(CGRectGetWidth(self.view.frame), 0.5)];
    UIImage *colorFourImage = [LJUtility imageWithColor:HEXCOLOR(0xDFE1E0) size:CGSizeMake(CGRectGetWidth(self.view.frame), 0.5)];
    
    //  设置底部Tabbar分割线颜色、宽度
    self.tabBar.backgroundImage = colorClearImage;
    self.tabBar.shadowImage = colorFourImage;
    self.tabBar.translucent = NO;
    self.tabBar.itemPositioning = UITabBarItemPositioningFill;
    
    NSArray<NSString *> *const controllerClassNames =   @[@"AppHomeController",
                                                        @"AppGoodsListController",
                                                        @"AppMyOrderListController",
                                                        @"PersonVC"];//AppMyCenterController,AppMyController
    
    NSArray<NSString *> *const titles = @[@"首页", @"商品列表", @"订单", @"我的"];
    NSArray<NSString *> *const normalImages = @[@"home",
                                                @"goodsList",
                                                @"orderList",
                                                @"My"];
    
    NSArray<NSString *> *const selectedImages = @[@"homeSelect",
                                                  @"goodsListSelect", @"orderListSelect",@"MySelect"];
    
    NSMutableArray *viewControllers = [NSMutableArray arrayWithCapacity:controllerClassNames.count];
    [controllerClassNames enumerateObjectsUsingBlock:^(NSString * _Nonnull className, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIViewController *viewController = [[NSClassFromString(className) alloc] init];
        //        //LYZB +
        //        if ([className isEqualToString:SameCityLifeController]) {
        //            [viewController setValue:SameCityLifeURL forKey:@"loadUrl"];
        //        }
        if ([className isEqualToString:@"PersonVC"]) {
            viewController = [[PersonVC alloc] init];
        }
        
        UINavigationController *navigarionController = [[UINavigationController alloc] initWithRootViewController:viewController];
        navigarionController.navigationBar.titleTextAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:15.0]};
        
        navigarionController.navigationBar.translucent = NO;
        
        [viewControllers addObject:navigarionController];
        [navigarionController.navigationBar setShadowImage:colorFourImage];
    }];
    
    self.viewControllers = viewControllers;
    
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull barButtonItem, NSUInteger idx, BOOL * _Nonnull stop) {
        
        barButtonItem.tag = 1000 + idx;
      
        barButtonItem.title = titles[idx];
        barButtonItem.imageInsets = UIEdgeInsetsZero;
        
        [barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0x666666), NSFontAttributeName: [UIFont systemFontOfSize:11.0]} forState:UIControlStateNormal];
        [barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0xF23030), NSFontAttributeName: [UIFont systemFontOfSize:11.0]} forState:UIControlStateSelected];
        
        barButtonItem.titlePositionAdjustment = UIOffsetMake(0, -2.0);
        barButtonItem.image = [[UIImage imageNamed:normalImages[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        barButtonItem.selectedImage = [[UIImage imageNamed:selectedImages[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }];
    
}


@end
